package com.monkeybrother.thread.callable;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

/**
 * @Desc
 * @Author houry
 * @Date 2021/4/5 14:56
 **/
public class FutureTest {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ExecutorService executor = Executors.newCachedThreadPool();
        System.out.println("~~~~~~~~~~~~~开始进行业务的计算~~~~~~~~~~~~~~");
        Future<String> first = executor.submit(new MyCallable(3, "hello！"));
        Future<String> second = executor.submit(new MyCallable(2, "可爱的小猴子，要加油哦！"));
        // 主线程可以继续执行一些其他的任务
        System.out.println("~~~~~~~主线程可以继续执行一些其他的任务~~~~~~~");
        System.out.println("最后的结果：" + first.get() + " " + second.get());
        executor.shutdown();
    }
}
